package buco.integrity.typehierarchy;

import java.util.HashSet;
import java.util.List;

public class ClassGraphWalker {
	HashSet<ClassNode> visitedNodes = new HashSet<ClassNode>(); 	
	
	public boolean findConnection(ClassNode from, ClassNode to) { 
		if(visitedNodes.contains(from))
			return false;
		
		List<ClassNode> subClasses = from.getSubClasses();
		visitedNodes.add(from);
		
		for(ClassNode subClass : subClasses) { 
			if(subClass.getClassName().equals(to.getClassName())) {
				return true;
			}
			if(findConnection(subClass, to)) { 
				return true; 
			}
		}
		return false;
	}
}
